package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.Aspect.UserPer;
import com.mc.read.adminapi.manager.PcUserManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/15 11:58
 */
@Service
@Slf4j
public class PcUserService {
    @Autowired
    PcUserManager pcUserManager;
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 用户列表展示 selectPcUserList
     **/
    @UserPer(permission = "pcuser:pcuser:select")
    @UserLog(operateName = "用户列表展示", type = 4)
    public BaseRespose selectPcUserList(BaseRequest baseRequest) {
        log.info("用户列表展示,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose=pcUserManager.selectPcUserList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("用户列表展示 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("用户列表展示 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     *修改用户禁用状态 updateUserStaus
     **/
    @UserPer(permission = "pcuser:pcuser:updateUserStaus")
    @UserLog(operateName = "修改用户禁用状态", type = 3)
    public BaseRespose updateUserStaus(BaseRequest baseRequest) {
        log.info("修改用户禁用状态,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose=pcUserManager.updateUserStaus(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("修改用户禁用状态 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改用户禁用状态 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

}
